// ActivexTestCtrl.cpp : Implementation of the CActivexTestCtrl ActiveX Control class.

#include "stdafx.h"
#include "ActivexTest.h"
#include "ActivexTestCtrl.h"
#include "ActivexTestPropPage.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


IMPLEMENT_DYNCREATE(CActivexTestCtrl, COleControl)



// Message map

BEGIN_MESSAGE_MAP(CActivexTestCtrl, COleControl)
	ON_MESSAGE(OCM_COMMAND, &CActivexTestCtrl::OnOcmCommand)
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
	ON_WM_CREATE()
END_MESSAGE_MAP()



// Dispatch map

BEGIN_DISPATCH_MAP(CActivexTestCtrl, COleControl)
	DISP_FUNCTION_ID(CActivexTestCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()



// Event map

BEGIN_EVENT_MAP(CActivexTestCtrl, COleControl)
END_EVENT_MAP()



// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CActivexTestCtrl, 1)
	PROPPAGEID(CActivexTestPropPage::guid)
END_PROPPAGEIDS(CActivexTestCtrl)



// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CActivexTestCtrl, "ACTIVEXTEST.ActivexTestCtrl.1",
	0x62924f3f, 0xc853, 0x4274, 0x94, 0x40, 0x96, 0x5f, 0x1e, 0x52, 0x4d, 0xa6)



// Type library ID and version

IMPLEMENT_OLETYPELIB(CActivexTestCtrl, _tlid, _wVerMajor, _wVerMinor)



// Interface IDs

const IID BASED_CODE IID_DActivexTest =
		{ 0xA464B3E4, 0xB37B, 0x48C7, { 0xA8, 0xA3, 0xE1, 0xE, 0x5F, 0x9, 0x98, 0xAC } };
const IID BASED_CODE IID_DActivexTestEvents =
		{ 0xCF0F7F05, 0x96DA, 0x40E9, { 0x95, 0x89, 0x93, 0x97, 0xA1, 0xFD, 0x22, 0x8C } };



// Control type information

static const DWORD BASED_CODE _dwActivexTestOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CActivexTestCtrl, IDS_ACTIVEXTEST, _dwActivexTestOleMisc)



// CActivexTestCtrl::CActivexTestCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CActivexTestCtrl

BOOL CActivexTestCtrl::CActivexTestCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_ACTIVEXTEST,
			IDB_ACTIVEXTEST,
			afxRegApartmentThreading,
			_dwActivexTestOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}



// CActivexTestCtrl::CActivexTestCtrl - Constructor

CActivexTestCtrl::CActivexTestCtrl()
{
	InitializeIIDs(&IID_DActivexTest, &IID_DActivexTestEvents);
	// TODO: Initialize your control's instance data here.
}



// CActivexTestCtrl::~CActivexTestCtrl - Destructor

CActivexTestCtrl::~CActivexTestCtrl()
{
	// TODO: Cleanup your control's instance data here.
}



// CActivexTestCtrl::OnDraw - Drawing function

void CActivexTestCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	if (!pdc)
		return;
	/*pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(GRAY_BRUSH)));
	pdc->Ellipse(rcBounds);*/
	DoSuperclassPaint(pdc, rcBounds);

	m_MainDialog.MoveWindow(rcBounds, TRUE);
	CBrush brBackGnd(TranslateColor(AmbientBackColor()));
	pdc->FillRect(rcBounds, &brBackGnd);
}



// CActivexTestCtrl::DoPropExchange - Persistence support

void CActivexTestCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.
}



// CActivexTestCtrl::OnResetState - Reset control to default state

void CActivexTestCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}



// CActivexTestCtrl::AboutBox - Display an "About" box to the user

void CActivexTestCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_ACTIVEXTEST);
	dlgAbout.DoModal();
}



// CActivexTestCtrl::PreCreateWindow - Modify parameters for CreateWindowEx

BOOL CActivexTestCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
	cs.lpszClass = _T("STATIC");//EDIT
	return COleControl::PreCreateWindow(cs);
}



// CActivexTestCtrl::IsSubclassedControl - This is a subclassed control

BOOL CActivexTestCtrl::IsSubclassedControl()
{
	return TRUE;
}



// CActivexTestCtrl::OnOcmCommand - Handle command messages

LRESULT CActivexTestCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
{
#ifdef _WIN32
	WORD wNotifyCode = HIWORD(wParam);
#else
	WORD wNotifyCode = HIWORD(lParam);
#endif

	// TODO: Switch on wNotifyCode here.

	return 0;
}



// CActivexTestCtrl message handlers

int CActivexTestCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	m_MainDialog.Create(IDD_MAINDIALOG, this);
	return 0;
}
